#include "const.h"

int loadtoolchainconf(const char *step) {
	static const char *filenames[] = {
		"$(toolchaindir)toolchain.conf",
		"$(toolchaindir)toolchain-$(targetarch).conf",
		"$(toolchaindir)toolchain-$(__STEP_).conf",
		"$(toolchaindir)toolchain-$(targetarch)-$(__STEP_).conf",
		"$(toolchaindir)toolchain-$(config)-$(__STEP_).conf",
		"$(toolchaindir)toolchain-$(config)-$(targetarch)-$(__STEP_).conf"
	};
	size_t i;
	char toolchainfile[512];
	int numfiles;

	v_setvar("__STEP_", step);
	numfiles = 0;

	for(i=0; i<sizeof(filenames)/sizeof(filenames[0]); i++) {
		v_nformat(toolchainfile, sizeof(toolchainfile), filenames[i]);

		if (isfile(toolchainfile)) {
			readconf(toolchainfile);
			numfiles++;
		}
	}

	return numfiles;
}
